package edu.towson.cosc.cosc455.kkarolenko.markdowncompiler;

import java.util.ArrayList;

// Node class for creating trees
// If a node is given a parent, that parent is given this node as a child
public class Node<T> {
	
	private T data;
	private Node<T> parent;
	private ArrayList<Node<T>> children = new ArrayList<Node<T>>();
	
	// constructor
	public Node(T data, Node<T> parent) {
		this.data = data;
		this.parent = parent;
		
		if (parent != null) {
			this.parent.addChild(this);
		}
	}
	
	// return the data
	public T getData() {
		return data;
	}
	
	// return the parent
	public Node<T> parent() {
		return parent;
	}
	
	// return the children
	public ArrayList<Node<T>> getChildren() {
		return children;
	}
	
	// add a child
	public boolean addChild(Node<T> child) {
		return children.add(child);
	}
}
